package com.juyu.miliao.api.service;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.juyu.miliao.api.dao.mysql.BlacklistDao;
import com.juyu.miliao.api.domain.Blacklist;
import com.juyu.miliao.common.exception.IllegalParamException;
import org.springframework.transaction.annotation.Transactional;

@Service
public class BlacklistService {
	@Resource
	private BlacklistDao blacklistDao;

	public void blacklistRelation(Blacklist entity) {
		if (entity.getType() == 1) {
			if(blacklistDao.findCountBlacklist(entity.getUserId(), entity.getBlacklistUserId()) !=0)
				throw new IllegalParamException("用户已拉黑");
			blacklistDao.addBlacklist(entity);
		} else {
			blacklistDao.removeBlacklist(entity);
		}
	}

	public String findCountBlacklist(long userId, long blacklistUserId) {
		String temp = "noRelation";
		if(blacklistDao.findCountBlacklist(userId, blacklistUserId) !=0){
			temp = "blacklistUser";
		}else if(blacklistDao.findCountBlacklist(blacklistUserId, userId) !=0){
			temp = "bePulledBlack";
		}
		return temp;
	}

}
